//
//  UIImageView+WebCache.swift
//  HotNews
//
//  Created by YYY on 2017/10/24.
//  Copyright © 2017年 成品家（北京）网路科技有限公司. All rights reserved.
//

import Foundation
import SDWebImage

extension UIImageView
{
    
    //设置图像
    /// 加载网络图像的二次封装
    ///
    /// - Parameters:
    ///   - urlString: urlString
    ///   - placeholderImage: 占位符图片
    ///   - isAvatar: 是否设置圆角
    func sd_setImageUrl(urlString: String?, placeholderString: String?, isAvatar: Bool = false)
    {
        let placeholderImage = UIImage(named: placeholderString ?? "")
        
        guard let urlString = urlString else {
            image = placeholderImage
            return
        }
        let url = URL(string: urlString)
        sd_setImage(with: url, placeholderImage: placeholderImage, options: [], progress: nil) { [weak self] (image, _, _, _) in
            //设置圆角
            if isAvatar
            {
                self?.image = image?.ovalImage(size: self?.bounds.size)
            }
        }
    }
}
